<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<div class="modal fade" id="ocean-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="width: 1000px; height: auto">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <c:choose>
                    <c:when test="${entity.id != null && entity.id!= ''}">
                        <h4 class="modal-title">编辑行政区划</h4>
                    </c:when>
                    <c:otherwise>
                        <h4 class="modal-title">新增行政区划</h4>
                    </c:otherwise>
                </c:choose>
            </div>
            <div class="modal-body">
                <div class=" form">
                    <form class="cmxform form-horizontal tasi-form" id="address_from" method="post"
                          data-url="resources/entity"
                          data-class="com.ocean.billboard.entity.BillboardAddress">
                        <div style="margin-left: 15%">
                            <input type="hidden" id="entity_id" name="id" value="${entity.id}">
                            <div>
                                <label for="name" class="control-label" >名称 </label>

                                    <input  id="name" name="name" type="text" placeholder="名称" value="${entity.name}"
                                           required/>

                            </div>
                            <input type="hidden" id="parentId" name="parentId" value="${entity.parentId}">
                            <input type="hidden" id="level" name="level" value="${entity.level==0?1:entity.level}">
                        </div>
                        <div style="float: left;margin-left: 60%;margin-top: -30px">
                            <div>
                                <label class="control-label">选择上级行政区划 </label>
                            </div>
                            <div>
                                <div id="groupTree" class="demo"></div>
                            </div>
                        </div>
                        <div class="form-group" style="margin-top: 8%">
                            <div class="col-lg-offset-2 col-lg-10">
                                <button class="btn btn-success" type="button" onclick="formSubmit(validator)">Save
                                </button>
                                <button class="btn btn-default" type="button" data-dismiss="modal">Cancel</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    var validator = $("#address_from").validate();
</script>
<script type="application/javascript" src="static/assets/jstree/jstree.min.js"></script>
<script type="application/javascript">
    $('#groupTree').jstree({
        'core': {
            'data': {
                "url": "resources/billboardAddress/treeData",
                "dataType": "json"
            }
        }
    }).on('changed.jstree', function (e, data) {
        console.log(data);
        if (data.action == 'select_node') {
            $("#parentId").val(data.node.id);
            $("#level").val(data.node.original.level + 1);
        }
    }).on('loaded.jstree', function (e, data) {
        $('#groupTree').jstree(true).select_node($("#parentId").val());
    });
</script>